export default {
  bind(el, binding, vnode) {
    const SELECT_DOM = el.querySelector('.el-select-dropdown .el-select-dropdown__wrap');

    SELECT_DOM.addEventListener('scroll', function () {
      const isAtTop = this.scrollTop === 0;
      const isAtBottom = this.scrollHeight - Math.ceil(this.scrollTop) <= this.clientHeight;

      // 执行滚动到顶部时需要的操作
      if (isAtTop) {
        binding.value('subtract');
      }

      // 执行滚动到底部时需要的操作
      if (isAtBottom) {
        binding.value('add');
      }
    });

    SELECT_DOM.addEventListener('wheel', function (event) {
      const isAtTop = this.scrollTop === 0;
      const isAtBottom = this.scrollHeight - Math.ceil(this.scrollTop) <= this.clientHeight;

      // 检测向上滚动并且已经处于顶部时
      if (isAtTop && event.deltaY < 0) {
        binding.value('subtract');
      }

      // 检测向下滚动并且已经处于底部时
      if (isAtBottom && event.deltaY > 0) {
        binding.value('add');
      }
    });
  },
};
